package com.jrx.anytxn.param.controller.couponReport;

import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import com.jrx.anytxn.param.dto.couponReport.TlCouponSummaryRes;
import com.jrx.anytxn.param.service.couponReport.ITlCouponSummaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jrx.auth.filter.service.InfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 优惠券发放汇总
 *
 * @author lbz
 */
@Api(tags = "页面优惠券发放汇总接口")
@RestController
@RequestMapping(value = "/param/couponSummary")
public class CouponSummaryController {

    private static final Logger logger = LoggerFactory.getLogger(CouponSummaryController.class);

    @Autowired
    private InfoService infoService;
    @Autowired
    private ITlCouponSummaryService tlCouponSummaryService;

    @ApiOperation(value = "分页查询优惠券发放汇总信息", notes = "分页查询优惠券发放汇总信息")
    @GetMapping(value = "/pageNum/{pageNum}/pageSize/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", required = true)})
    public TxnRespResult<TxnPage<TlCouponSummaryRes>> getAllPageByTenId(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize) {
        TxnRespResult<TxnPage<TlCouponSummaryRes>> result = new TxnRespResult<>();
        TxnPage<TlCouponSummaryRes> response;
        try {
            String tenantId=String.valueOf(infoService.getUser().getProjectId());
            response = tlCouponSummaryService.findAllPageByTenantId(pageNum, pageSize, tenantId);
            result.getSuccess(response);
        } catch (TxnException e) {
            logger.error(e.getMessage(),e);
            result.getFail(e.getErrCode(), e.getMessage());
        }
        return result;
    }

}
